package tazadum.engine.math;

import java.nio.FloatBuffer;

public class Hexagon {
	private static final float sideRatio = (float) (Math.sqrt(3) / 2);

	public static float side(final float radius) {
		return radius * sideRatio;
	}

	public static void generate(final Vector[] dest, final Vector center, final float radius) {
		int i = 0;
		for (float angle = 0; angle < 360; angle += 60) {
			if (dest[i] == null) {
				dest[i] = new Vector();
			}
			final float radians = (float) (angle * Math.PI / 180f);
			dest[i].x = (float) Math.cos(radians) * radius + center.x;
			dest[i].y = (float) Math.sin(radians) * radius + center.y;
			dest[i].z = center.z;
			i++;
		}
	}

	public static void generate(final FloatBuffer buffer, final Vector center, final float radius) {
		int i = 0;
		for (float angle = 0; angle < 360; angle += 60) {
			final float radians = (float) (angle * Math.PI / 180f);
			buffer.put((float) Math.cos(radians) * radius + center.x);
			buffer.put((float) Math.sin(radians) * radius + center.y);
			buffer.put(center.z);
			i++;
		}
	}
}
